package com.ruoyi.common.utils;


import com.alibaba.fastjson.JSON;

import java.util.Map;

/**
 * @program: mario-parent
 * @author: MaH
 * @create: 2020-04-16 09:37
 * 从请求参数中获取分页的页码和页长；报错则默认页面为1，页长为10
 **/
public class PageKit {
    public static int getPage(Map<String, Object> params) {
        try {
            return Integer.parseInt(params.get("page").toString());
        } catch (Exception e) {
        }
        return 1;
    }

    public static int getSize(Map<String, Object> params) {
        try {
            return Integer.parseInt(params.get("size").toString());
        } catch (Exception e) {
        }
        return 10;
    }

    public static <T> T getQueryBean(Map<String, Object> params, Class<T> clazz) {
        try {
            return JSON.parseObject(JSON.toJSONString(params), clazz);
        } catch (Exception e) {
            try {
                return (T) Class.forName(clazz.getName());
            } catch (ClassNotFoundException ex) {
                ex.printStackTrace();
            }
        }
        return null;
    }
}
